from selenium import webdriver
import time
from selenium.webdriver.common.by import  By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import NoSuchAttributeException
browser=webdriver.Chrome()
# try:
#     browser.get('http://baidu.com')
#     input=browser.find_element_by_id('kw')
#     input.send_keys('python')
#     input.send_keys(Keys.ENTER)
#     wait=WebDriverWait(browser,10)
#     wait.until(EC.presence_of_all_elements_located((By.ID,'content_left')))
#     print(browser.current_url)
#     print(browser.get_cookies())
#     print(browser.page_source)
# finally:
#     browser.close()

# browser.get('https://www.taobao.com')
# lis=browser.find_elements_by_css_selector('.service-bd li')
# print(lis)
# browser.close()
# input=browser.find_element_by_id('q')
# input.send_keys('iphone')
# time.sleep(1)
# input.clear()
# input.send_keys('ipad')
# button=browser.find_element_by_class_name('btn-search')
# # button.click()
# input.send_keys(Keys.ENTER)

from selenium.webdriver import ActionChains
# url="http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable"
# browser.get(url)
# browser.switch_to.frame('iframeResult')
# source=browser.find_element_by_css_selector('#draggable')
# target=browser.find_element_by_css_selector('#droppable')
# action=ActionChains(browser)
# action.drag_and_drop(source,target)
# action.perform()

# url='https://www.zhihu.com/explore'
# browser.get(url)
# logo=browser.find_element_by_id('zh-top-link-logo')
# print(logo.get_attribute('class'))
# input=browser.find_element_by_class_name('zu-top-add-question')
# print(input.text,input.id,input.location,input.tag_name,input.size)

# url='http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'
# browser.get(url)
# time.sleep(2)
# browser.switch_to.frame('iframeResult')
# time.sleep(2)
# try:
#     logo=browser.find_element_by_class_name('logo')
# except NoSuchAttributeException:
#     print('NO LOGO')

# browser.switch_to.parent_frame()
# logo=browser.find_element_by_class_name('logo')
# print(logo)
# print(logo.text)

# browser.get('https://www.baidu.com/')
# browser.get('https://www.taobao.com/')
# wait=WebDriverWait(browser,10)
# input=wait.until(EC.presence_of_all_elements_located((By.ID,'q')))
# print(input)
# browser.get('https://www.python.com/')
# browser.back()
# time.sleep(1)
# browser.forward()
# browser.close()

# browser.get('http://zhihu.com/explore')
# print(browser.get_cookies())
# browser.add_cookie({'name':'name','domain':'www.zhihu.com','value':'germey'})
# print(browser.get_cookies())

browser.get('http://baidu.com/explore')
browser.execute_script('window.open()')
print(browser.window_handles)
browser.switch_to.window(browser.window_handles[1])
browser.get('http://taobao.com')
time.sleep(1)
browser.switch_to.window(browser.window_handles[0])
browser.get('http://python.org')
docker run -p 8050:8050 scrapinghub/splash